package com.cnt.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cnt.entity.UserInfo;
import com.cnt.vo.UserResultVo.UserInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserInfoDao extends BaseMapper<UserInfo> {

    @Select("select * from user_info where user_id= #{userId}")
    public UserInfo selectByUserId(Integer userId);

    @Update("update user_info set image = #{targetPath} where user_id= #{userId}")
    public Integer updateImage(Integer userId, String targetPath);

    @Select("SELECT \n" +
            "  u.user_id AS userId,\n" +
            "  ui.gender,\n" +
            "  ui.email,\n" +
            "  ui.address,\n" +
            "  ui.bank,\n" +
            "  ui.bank_card_number AS bankCardNumber,\n" +
            "  ui.image,\n" +
            "  u.id_card AS idCard,\n" +
            "  u.name,\n" +
            "  u.account,\n" +
            "  ui.age,\n" +
            "  ui.phone,\n" +
            "  u.user_role AS userRole,\n" +
            "  ui.charitable_score AS charitableScore\n" +
            "FROM USER u\n" +
            "JOIN user_info ui ON u.user_id = ui.user_id where u.user_id = #{userId}\n")
    UserInfoVo getUserInfoVo(Integer userId);

    @Select("SELECT \n" +
            "  u.user_id AS userId,\n" +
            "  ui.gender,\n" +
            "  ui.email,\n" +
            "  ui.address,\n" +
            "  ui.bank,\n" +
            "  ui.bank_card_number AS bankCardNumber,\n" +
            "  ui.image,\n" +
            "  u.id_card AS idCard,\n" +
            "  u.name,\n" +
            "  u.account,\n" +
            "  ui.age,\n" +
            "  ui.phone,\n" +
            "  u.user_role AS userRole,\n" +
            "  ui.charitable_score AS charitableScore\n" +
            "FROM USER u\n" +
            "JOIN user_info ui ON u.user_id = ui.user_id where u.user_role in (1,2)\n")
    public List<UserInfoVo> getAdministrators();
}
